#include <iostream>
using namespace std;
class Student
{
private:
    int n;
    int a;
    int b;
    int c;
    int sum;

public:
    Student(int n_ = 0, int a_ = 0, int b_ = 0, int c_ = 0) : n(n_), a(a_), b(b_), c(c_)
    {
        sum = a + b + c;
    }
    int GetN() { return n; }
    int GetA() { return a; }
    int GetB() { return b; }
    int GetC() { return c; }
    int GetSum() { return sum; }
    friend bool operator>(Student &A, Student &B)
    {
        if (A.sum > B.sum)
        {
            return true;
        }
        else if (A.sum == B.sum)
        {
            if (A.a > B.a)
            {
                return true;
            }
            else if (A.a == B.a)
            {
                return A.n < B.n;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
};
template <typename T>
long Divide(T arr[], long p, long r)
{
    T x = arr[r - 1];
    long i = p - 1;
    for (int j = p; j < r - 1; j++)
    {
        if (arr[j] > x)
        {
            i++;
            swap(arr[j], arr[i]);
        }
    }
    swap(arr[i + 1], arr[r - 1]);
    return i + 1;
}
template <typename T>
void QuickSort(T arr[], long p, long r)
{
    if (p < r)
    {
        long q = Divide(arr, p, r);
        QuickSort(arr, p, q);
        QuickSort(arr, q + 1, r);
    }
}
int main()
{
    int n;
    cin >> n;
    int a, b, c;
    Student *S = new Student[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b >> c;
        S[i] = Student(i + 1, a, b, c);
        // cout << S[i].GetN() << " " << a << " " << b << " " << c << endl;
    }
    QuickSort(S, 0, n);
    for (int i = 0; i < 5; i++)
    {
        cout << S[i].GetN() << " " << S[i].GetSum() << endl;
    }
    return 0;
}